{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "50\n"
     ]
    }
   ],
   "source": [
    "def product(x,y):\n",
    "    return x*y\n",
    "print(product(2,3))\n",
    "print(product(5,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome to QuantConnect\n"
     ]
    }
   ],
   "source": [
    "def say_hi():\n",
    "    print('Welcome to QuantConnect')\n",
    "say_hi()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "range(0, 10)\n",
      "range(1, 11)\n",
      "range(1, 11, 2)\n"
     ]
    }
   ],
   "source": [
    "print(range(10))\n",
    "print(range(1,11))\n",
    "print(range(1,11,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The length of tickers is 8\n",
      "AAPL\n",
      "GOOG\n",
      "IBM\n",
      "FB\n",
      "F\n",
      "V\n",
      "G\n",
      "GE\n"
     ]
    }
   ],
   "source": [
    "tickers = ['AAPL','GOOG','IBM','FB','F','V', 'G', 'GE']\n",
    "print('The length of tickers is {}'.format(len(tickers)))\n",
    "for i in range(len(tickers)):\n",
    "    print(tickers[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4, 4, 3, 2, 1, 1, 1, 2]\n"
     ]
    }
   ],
   "source": [
    "tickers = ['AAPL','GOOG','IBM','FB','F','V', 'G', 'GE']\n",
    "print(list(map(len,tickers)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(lambda x: x**2, range(10)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[6, 6, 6, 6, 6]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(lambda x, y: x+y, [1,2,3,4,5],[5,4,3,2,1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted([5,2,3,4,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('MSFT', 69), ('WMT', 75.32), ('AAPL', 144.09), ('FB', 150), ('GOOG', 911.71)]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price_list = [('AAPL',144.09),('GOOG',911.71),('MSFT',69),('FB',150),('WMT',75.32)]\n",
    "sorted(price_list, key = lambda x: x[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('GOOG', 911.71), ('FB', 150), ('AAPL', 144.09), ('WMT', 75.32), ('MSFT', 69)]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price_list = [('AAPL',144.09),('GOOG',911.71),('MSFT',69),('FB',150),('WMT',75.32)]\n",
    "sorted(price_list, key = lambda x: x[1],reverse = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('MSFT', 69), ('WMT', 75.32), ('AAPL', 144.09), ('FB', 150), ('GOOG', 911.71)]\n"
     ]
    }
   ],
   "source": [
    "price_list = [('AAPL',144.09),('GOOG',911.71),('MSFT',69),('FB',150),('WMT',75.32)]\n",
    "price_list.sort(key = lambda x: x[1])\n",
    "print(price_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "class stock:\n",
    "    def __init__(self, ticker, open, close, volume):\n",
    "        self.ticker = ticker\n",
    "        self.open = open\n",
    "        self.close = close\n",
    "        self.volume = volume\n",
    "        self.rate_return = float(close)/open - 1\n",
    " \n",
    "    def update(self, open, close):\n",
    "        self.open = open\n",
    "        self.close = close\n",
    "        self.rate_return = float(self.close)/self.open - 1\n",
    " \n",
    "    def print_return(self):\n",
    "        print(self.rate_return)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "apple = stock('AAPL', 143.69, 144.09, 20109375)\n",
    "google = stock('GOOG', 898.7, 911.7, 1561616)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.014465338822744034\n",
      "0.0006573181419806673\n"
     ]
    }
   ],
   "source": [
    "apple.ticker\n",
    "google.print_return()\n",
    "google.update(912.8,913.4)\n",
    "google.print_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Tim Cook'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "apple.ceo = 'Tim Cook'\n",
    "apple.ceo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['__class__',\n",
       " '__delattr__',\n",
       " '__dict__',\n",
       " '__dir__',\n",
       " '__doc__',\n",
       " '__eq__',\n",
       " '__format__',\n",
       " '__ge__',\n",
       " '__getattribute__',\n",
       " '__gt__',\n",
       " '__hash__',\n",
       " '__init__',\n",
       " '__init_subclass__',\n",
       " '__le__',\n",
       " '__lt__',\n",
       " '__module__',\n",
       " '__ne__',\n",
       " '__new__',\n",
       " '__reduce__',\n",
       " '__reduce_ex__',\n",
       " '__repr__',\n",
       " '__setattr__',\n",
       " '__sizeof__',\n",
       " '__str__',\n",
       " '__subclasshook__',\n",
       " '__weakref__',\n",
       " 'ceo',\n",
       " 'close',\n",
       " 'open',\n",
       " 'print_return',\n",
       " 'rate_return',\n",
       " 'ticker',\n",
       " 'update',\n",
       " 'volume']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(apple)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "class child(stock):\n",
    "    def __init__(self,name):\n",
    "        self.name = name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aa\n",
      "100\n",
      "102\n",
      "0.020000000000000018\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "aa = child('aa')\n",
    "print(aa.name)\n",
    "aa.update(100,102)\n",
    "print(aa.open)\n",
    "print(aa.close)\n",
    "print(aa.print_return())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
